package views;

import javax.swing.*;

import common.Contexto;
import controllers.IErrorObserver;
import controllers.ReservasController;
import controllers.SociosController;
import business.interfaces.ICalendarioReserva;
import business.interfaces.ICliente;
import business.interfaces.ISocio;
import data.entities.CalendarioReserva;
import data.entities.Cliente;
import data.entities.Socio;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@SuppressWarnings("serial")
public class SocioTablePanel extends JPanel  implements IErrorObserver {
    private JTable table;
    private JButton selectB, cancelB;
    private Action selectA, cancelA;
    private JPanel buttons;
    private List<ISocio> socios;
    private SociosTableModel tableModel;
    private SociosController controller;

    public SocioTablePanel() {
    	controller = new SociosController();
    	socios = controller.getSocios();
    	this.controller.agregarErrorObserver(this);
        init();
    }

    private void init() {
    	this.setLayout(new BorderLayout());
    	initActions();
    	createTable();	

        buttons = new JPanel();
        selectB = new JButton(selectA);
        cancelB = new JButton(cancelA);
        
        
        //buttons.add(selectB);
        buttons.add(cancelB);;
        add(buttons, BorderLayout.SOUTH);
    }

    public void createTable() {
        tableModel = new SociosTableModel(socios);
        table = new JTable(tableModel);

        table.setPreferredScrollableViewportSize(new Dimension(500, 70));
        JScrollPane scrollPane = new JScrollPane(table);
        add(scrollPane, BorderLayout.CENTER);
    }
    
    /**
     * Se inicializan las acciones utilizadas en los botones de la pantalla 
     */
	private void initActions(){
    	cancelA = new AbstractAction("Volver") {

            public void actionPerformed(ActionEvent e) {
            	SwingUtilities.windowForComponent(SocioTablePanel.this).dispose();
            }
        };
        
        selectA = new AbstractAction("Editar") {

            public void actionPerformed(ActionEvent e) {
            	
            }
        };
    }
	
	public void showPanel() {
		socios = controller.getSocios();
    	JFrame ubicacionesFrame = new JFrame();
        ubicacionesFrame.setTitle("Socios");
        ubicacionesFrame.getContentPane().add(this);
        ubicacionesFrame.setPreferredSize(new Dimension(700,240));
        ubicacionesFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        ubicacionesFrame.pack();
        ubicacionesFrame.setLocationRelativeTo(null);
        ubicacionesFrame.setVisible(true);
    }

	@Override
	public void notificarError(String error) {
		Contexto.displayErrorMessage(this, error);
	}
}



















